@extends('app')
@include('UEditor::head')
@section('content')
<ul class="nav nav-tabs">
    <li class="active"><a href="{{ url('/admin/content/ads')}}">信息列表</a></li>
    <li><a href="{{ url('/admin/content/ads/create') }}">信息添加</a></li>
</ul>
<form id="newsForm" method="post" action="/admin/content/ads">
    <div class="description2">
        <div class="form-group">
            <!--             <label for="title" class="col-sm-2 control-label">标题：</label> -->
            <!--             <div class="col-sm-10"> -->
            <input type="text" class="form-control" name="title" id="title" placeholder="广告名称"
                   value="{{ $ads->title }}">
            <!--             </div> -->
        </div>

        <div class="form-group">
            <label>广告位：</label>
            <select name="position_id" class="form-control" id="position_id">
                <option value="0">--无--</option>
                @foreach($position as $po)
                <option value="{{ $po->id }}" @if($ads->position_id == $po->id) selected @endif>{{ $po->title }}</option>
                @endforeach
            </select>
        </div>

        <div class="form-group">
            <label>所属应用：</label>
            <select name="app" class="form-control" id="app">
                <option value="0">--无--</option>
                @foreach($app as $k => $item)
                <option value="{{ $k }}" @if($ads->app == $k) selected @endif>{{ $item }}</option>
                @endforeach
            </select>
        </div>

        <div class="form-group">
            <label>类型：</label>
            <input type="radio" class="adstype" name="type" value="0" @if($ads->type == 0) checked @endif>  图片
            <input type="radio" class="adstype" name="type" value="1" @if($ads->type == 1) checked @endif>     文字
        </div>


        <div id="ads_attach" @if($ads->type != 0)style="display:none;"@endif>
            <h5>图片：</h5>
            <div class="form-group">
                <input id="uploadimg" name="uploadimg" type="file" multiple="true">
                <div id="imgbox" class="dustbin">
                    @if($ads->type == 0)
                    <div style="width:90px; height:60px;float:left;">
                        <img src='{{ $attach->url }}' />
                        <input type='hidden' name='thumb' value='{{ $attach->aid }}' />
                    </div>
                    @endif
                </div>
            </div>
        </div>

        <div class="form-group">
            <label>链接：</label>
            <input type="text" class="form-control" name="advurl" id="advurl"
                   value="{{ $ads->advurl }}" placeholder="" style="width: 400px;">
        </div>

        <div class="form-group">
            <label>描述：</label>
            <textarea class="form-control" rows="3" name="content">{{ $ads->content }}</textarea>
        </div>

        <div class="form-group">
            <label>是否有效：</label>
            <input type="radio" name="is_active" value="1" @if($ads->is_active == 1) checked @endif>    是
            <input type="radio" name="is_active" value="0" @if($ads->is_active == 0) checked @endif>       否
        </div>
        <div class="form-group">
            <label>是否关闭：</label>
            <input type="radio" name="is_closed" value="0" @if($ads->is_closed == 0) checked @endif> 是
            <input type="radio" name="is_closed" value="1" @if($ads->is_closed == 1) checked @endif> 否
        </div>
        <div class="form-inline mt20">
            <div class="form-group">
                <label>排序：</label>
                <input type="text" class="form-control" name="sort" id="sort"
                       value="{{ $ads->sort }}" placeholder="" style="width: 100px;">
            </div>
        </div>
        {!! csrf_field() !!}
        <input type="hidden" name="id" value="{{ $ads->id }}">
        <div class="form-inline mt20">
            <div class="form-group">
                <input type="submit" class="btn btn-primary btn-block" id="organi_publish_save" value="保存并发布" />
            </div>
            <div class="form-group col-xs-offset-1">
                <input type="submit"  class="btn  btn-default btn-block" id="employ_no_publish_save" value="保存" />
            </div>

            <div class="form-group col-xs-offset-1">
                <input type="reset" class="btn btn-default btn-block" value="重置" />
            </div>
        </div>
    </div>
</form>

<script type="text/javascript">
    <!--
    $(document).ready(function(){
    	$('input').iCheck({
    		checkboxClass: 'icheckbox_flat-blue',
    	    radioClass: 'iradio_flat-blue',
    	    increaseArea: '-10' // optional
    	});

        /*广告不同类型处理，iCheck绑定事件*/
        $('.adstype').on('ifChecked', function(event){
            var adstype = $(this).val();
            if(adstype == 0) {
                $('#ads_attach').css('display','');
            } else {
                $('#ads_attach').css('display','none');
            }
        });

        /***图片上传****/
        $("#uploadimg").uploadify({
            'formData'     : {
                'app':'ads',
                'fileField':'upfile',
                '_token':'{{ csrf_token() }}'
            },
            "width"           : 120,
            "height"          : 30,
            "queueSizeLimit"  :1,
            "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
            "fileObjName"     : "upfile",
            "buttonText"      : "上传图片",
            "uploader"        : '/admin/upload/uploadimg',
            'removeTimeout'	  : 1,
            'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
            'onUploadSuccess':function(file, data, response){
                var data = eval('(' + data + ')');
                if (data.status == 'success') {

                    var html="<div style='width:90px; height:60px;float:left;'>"
                        +"<img src='"+data.attach+"' /><input type='hidden' name='thumb' value='"+data.attach_id+"' />"
                        +"</div>"
                    $('#imgbox').html(html);
//     	            bindImg();
                }else{
                    alert(data.msg);
                    return false;
                }

            }

        });
    });
    //-->
</script>
@endsection
